using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Example.Business;

namespace www
{
    public partial class Search_ByAvailability : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItem != null)
            {
                Beer b = (Beer)e.Row.DataItem;

                HyperLink companyLink = (HyperLink)e.Row.FindControl("CompanyLink");
                HyperLink styleLink = (HyperLink)e.Row.FindControl("StyleLink");

                companyLink.Text = b.Company.Name;
                styleLink.Text = b.Style.Name;
            }
        }
        protected void AvailabilityEntitySource_Select(object sender, NBusiness.Data.Web.SelectEntityEventArgs e)
        {
            e.Entities = AvailabilityCollection.FetchAll();
        }
        protected void BeerEntitySource_Select(object sender, NBusiness.Data.Web.SelectEntityEventArgs e)
        {
            int availabilityId;
            if (int.TryParse(Request["a"], out availabilityId) &&
                availabilityId > 0)
            {
                int totalRows = 0;
                e.Entities = BeerCollection.FetchByAvailability(
                    availabilityId,
                    e.StartIndex,
                    e.MaxRows,
                    e.SortField,
                    e.SortOrder,
                    out totalRows);
                e.TotalRows = totalRows;
            }
        }
        protected void DropDownList1_DataBound(object sender, EventArgs e)
        {
            int availabilityId;
            if (int.TryParse(Request["a"], out availabilityId) && availabilityId > 0)
            {
                DropDownList1.SelectedValue = availabilityId.ToString();
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Search/ByAvailability.aspx?a=" + DropDownList1.SelectedValue);
        }
    }
}